<?php

namespace app\controller\web;


use app\model\exam\Record;

/**
 * @ApiInternal ()
 */
class WrongQuestion extends Common
{
    public function list()
    {
        $pageSize = $this->request->post('page_size', 10);
        $uId = $this->getLoginUserInfo()['id'];
        $recordModel = new Record();
        $questionModel = new \app\model\Questions();

        $result = $recordModel->where('student_id', $uId)->where('is_right', 2)->order('id', 'desc')
            ->field('exam_id, papers_id, question_id, num, answer as you_answer, is_right, type, create_time')
            ->paginate($pageSize)->toArray();

        $qIds = [];
        foreach ($result['data'] as $val) {
            $qIds[] = $val['question_id'];
        }

        $questionList = $questionModel->where('id', 'in', $qIds)
            ->column('id, type, title, anwser, analysis, category_id, course_id', 'id');

        foreach ($result['data'] as &$val) {
            $val['title'] = $questionList[$val['question_id']]['title'] ?? [];
            $val['type'] = $this->getQuestionTypeStr($questionList[$val['question_id']]['type']);
            $val['answer'] = $questionList[$val['question_id']]['anwser'] ?? '';
            $val['analysis'] = $questionList[$val['question_id']]['analysis'] ?? '暂无解析';
        }
        return $this->success('数据获取成功', $result);
    }
}